﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!-- The instances of the Item class will be stored in the "Item" table -->
<class
	name="NCommet.Core.Item, NCommet.Core"
	table="Item" lazy="true">

	<!-- Identity -->
	<id
		name="id" access="field"
		column="ID" type="Int32" unsaved-value="0">
		<generator class="identity" />
	</id>

	<!-- Fields -->
	<property
		name="name" access="field"
		column="Name" type="String" length="250" not-null="true" />
	<property
		name="itemType" access="field"
		column="ItemType" type="String" length="50" not-null="false" />
	<property
		name="order" access="field"
		column="SortOrder" type="Int32" not-null="true" />
	<property
		name="createdAt" access="field"
		column="CreatedAt" type="DateTime" not-null="true" />

	<!-- Field "parent": Many-to-One association between children Items and their parent Item. -->
	<many-to-one
		name="parent" access="field"
		column="parent_id" not-null="false"
		class="NCommet.Core.Item, NCommet.Core" cascade="none" unique="false" />

	<!-- Field "_internalChildren": One-to-Many association between the parent Item and its children Items. -->
	<list
		name="_internalChildren" access="field"
		table="Item" cascade="all" inverse="true"
		generic="true" batch-size="20">
		<key column="parent_id" />
		<index column="SortOrder" type="Int32" />
		<one-to-many class="NCommet.Core.Item, NCommet.Core" />
	</list>

	<!-- Field "tags": The strings will be stored in the "ItemTag" table -->
	<bag
		name="tags" access="field"
		table="ItemTag">
		<key column="item_id"/>
		<element column="tag" type="String" length="50" not-null="true" />
	</bag>

	<!-- Field "_internalRelatives": One-to-Many association between the subject Item and its relatives. -->
	<bag
		name="_internalRelatives" access="field"
		table="ItemRel" cascade="all-delete-orphan" inverse="true">
		<key column="subject_item_id" />
		<one-to-many class="NCommet.Core.RelItem, NCommet.Core" />
	</bag>
	
	<!-- Field "content": One-to-One association between an Item and its ContentBase object. -->
	<one-to-one
		name="content" access="field"
		class="NCommet.Core.ContentBase, NCommet.Core" cascade="all" />

</class>
</hibernate-mapping>

